package com.controller;

import com.pojo.Result;
import com.service.NoteTagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/note-tags")
public class NoteTagsController {

    @Autowired
    private NoteTagsService noteTagsService;

    @PostMapping
    public Result<Void> addTagToNote(
            @RequestParam Integer noteId,
            @RequestParam Integer tagId) {
        return noteTagsService.addTagToNote(noteId, tagId);
    }

    @DeleteMapping
    public Result<Void> removeTagFromNote(
            @RequestParam Integer noteId,
            @RequestParam Integer tagId) {
        return noteTagsService.removeTagFromNote(noteId, tagId);
    }

    @DeleteMapping("/note/{noteId}")
    public Result<Void> removeAllTagsFromNote(@PathVariable Integer noteId) {
        return noteTagsService.removeAllTagsFromNote(noteId);
    }

    @DeleteMapping("/tag/{tagId}")
    public Result<Void> removeTagFromAllNotes(@PathVariable Integer tagId) {
        return noteTagsService.removeTagFromAllNotes(tagId);
    }

    @GetMapping("/note/{noteId}/tags")
    public Result<List<Integer>> getTagsByNoteId(@PathVariable Integer noteId) {
        return noteTagsService.getTagsByNoteId(noteId);
    }

    @GetMapping("/tag/{tagId}/notes")
    public Result<List<Integer>> getNotesByTagId(@PathVariable Integer tagId) {
        return noteTagsService.getNotesByTagId(tagId);
    }

    @GetMapping("/exists")
    public Result<Boolean> isTagAttachedToNote(
            @RequestParam Integer noteId,
            @RequestParam Integer tagId) {
        return noteTagsService.isTagAttachedToNote(noteId, tagId);
    }
}